package cn.piesat.scanning.business.xz.service.snwimpl;

import cn.piesat.scanning.business.xz.service.BuildAlgorithmTaskService;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskPathParam;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskRuleParam;
import cn.piesat.scanning.dto.HtScanningMetadataDTO;
import cn.piesat.scanning.service.HtScanningMetadataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Ming
 * @version 1.0
 * @description: TODO
 * @date 2023/12/18 13:48
 */
@Service
public class Build01_SNSDServiceImpl implements BuildAlgorithmTaskService {
    @Autowired
    private HtScanningMetadataService htScanningMetadataService;
    @Override
    public Map<String, Object> initAlgorithmParams(String adsType, String primaryFile, String filePath,
                                                   AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam,
                                                   Map<String, Integer> indexParams, String fileDate, String scanningPath,HtScanningMetadataDTO htScanningMetadataDTO) {
        Map<String, Object> algorithmParams = new HashMap<>();
        //FY3D_MWRIA_GBAL_L1A_GLL_20231224_0000_0010KM.NC
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);

        String[] s = fileName.split("_");
        String satellite = s[0].replace("-", "");
        String region = s[2].replace("-", "");

        HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetaDataDto(fileDate, "L3", satellite,
                taskPathParam.getParameter06(), "540000", "TIFF", "SNW");


        Map<String, Object> params = new HashMap<>();
        params.put("primaryFile", primaryFile);
        params.put("sysname", taskPathParam.getParameter04());
        params.put("snwc_file", taskPathParam.getParameter02() + metadataDTO.getFilePath());
        params.put("auxpath", taskPathParam.getParameter03());
        params.put("prod_name", taskPathParam.getParameter05());
        params.put("dataType", taskPathParam.getParameter07());
        algorithmParams.put("parameter00", adsType);
        algorithmParams.put("parameter01", params);
        return algorithmParams;
    }
}
